/**
 * 判断参数是否为null/""
 */
function judgeParamHasNull(param){
	var res = {};
	res['flag']=true;
	for(var key in param){
		if(!param[key]){
			res['name']=key;
			res['flag']=false;
			break;
		}
	}
	return res;
}

function formatGetUrl(url,param){
	var i = 0;
	for(var key in param){
		if(i==0&&url.indexOf("?")==-1){
			url = url+"?"+ key+"="+param[key]
		}else{
			url = url+"&"+ key+"="+param[key]
		}
		i++;
	}
	return url;
}

function executeAjaxByGet(url,param){
	var res = []
	jQuery.ajax({
		url: formatGetUrl(url,param),
		type: "get",
		async: false,
		dataType: "json",
		success: function (data) {

			res=data;
		},
		error: function (XMLHttpRequest, textStatus, errorThrown, XMLHttpResponse) {
            console.log(XMLHttpRequest)
            var readyState=XMLHttpRequest.readyState;
            if(readyState==4){
                var text = XMLHttpRequest.responseText;
                if(text.indexOf("<html")>-1){
                    window.location.reload();
                }
            }else{
                alert("获取数据失败！");
            }
		}
	});
	return res;
}

function executeAjaxByPost(url,param){
	var flag;
	jQuery.ajax({
		url: url,
		type: "post",
		data:param,
		async: false,
		dataType: "json",
		success: function (data) {
			flag=data;
		},
		error: function (XMLHttpRequest, textStatus, errorThrown, XMLHttpResponse) {
            console.log(XMLHttpRequest)
            var readyState=XMLHttpRequest.readyState;
            if(readyState==4){
                var text = XMLHttpRequest.responseText;
                if(text.indexOf("<html")>-1){
                    window.location.reload();
                }
            }else{
                alert("获取数据失败！");
            }
		}
	});
	return flag;
}

function getTypeValue(name){
	var val=0;
	jQuery.each($("input[name='"+name+"']"),function(i,n){
		if(n.checked) {
			val=$(this).attr("value");
		}
	});
	return val;
}

function getTypeValueForList(name){
	var val = new Array();
	jQuery.each($("input[name='"+name+"']"),function(i,n){
		if(n.checked) {
			val.push($(this).attr("value"));
		}
	});
	return val;
}



function getSearchParam(){
	var paramStr = location.search;
	if(paramStr.indexOf("id")>-1){
        var str = paramStr.substr(1);
        var strs = str.split("&");
        for(var i = 0; i < strs.length; i ++) {
            var paramPair = strs[i].split("=")
            if(paramPair[0]=='id'){
                paramStr=paramStr.replace("id="+paramPair[1]+"&","");
                break;
			}
        }
	}
	return paramStr;
}
function parseParam(data) {
	var url = location.search;
    if (url.indexOf("?") != -1) {
        var str = url.substr(1);
        strs = str.split("&");
        for(var i = 0; i < strs.length; i ++) {
        	var paramPair = strs[i].split("=")
			var p = paramPair[1]
			if(p=='false'){
        		p=false
			}else if(p=='true'){
				p=true;
			}else{
				p=decodeURIComponent(p);
			}

            data[paramPair[0]]=p;
        }
    }
}


//name就是参数名 函数返回参数值
function getQueryString(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
	var r = window.location.search.substr(1).match(reg);
	if (r != null) return unescape(r[2]);
	return null;
}

function checkoutAuth(permissionCode)
{
    var cookie=document.cookie.substr(document.cookie.indexOf('permission=')+11).split('#');
    var i = cookie.length;
    while (i--) {
        if (cookie[i] === permissionCode) {
            return true;
        }
    }
    return false;
}


function batchChangeStatus(status,url){
    var ids = getTypeValueForList('selectChecked');
    if(ids.length==0){
        alert('请勾选选项！');
        return;
    }
	var pm={ids:ids.join(","),status:status}
	var ret = executeAjaxByPost(url,pm)
	alert(ret.msg);
    demo.search();
}
